<?php
namespace app\common\controller;

/**
 * 社区巡店排行榜类（月）
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/09/25
 * Time: 14:30
 */
class CpRankMonth{

    /**
     * 计算用户社区巡店排名
     * @param $cp_user_num
     * @return int
     */
    public function count_cp_user_ranking($cp_user_num){
        $month_time = get_month_time();
        $start_date = date('Y-m',strtotime($month_time['start_time']));

        $maps = [];
        $maps[] = ['timeid','=',$start_date];
        $maps[] = ['cp_user_num','>',$cp_user_num];
        $ranking = model('cp_form_user_month')->get_count($maps,'id');
        if(empty($ranking)){
            $ranking = 0;
        }
        return $ranking + 1;
    }

    /**
     * 计算分部社区巡店排名
     * @param $cp_branch_num
     * @return int
     */
    public function count_cp_branch_ranking($cp_branch_num){
        $month_time = get_month_time();
        $start_date = date('Y-m',strtotime($month_time['start_time']));

        $maps = [];
        $maps[] = ['timeid','=',$start_date];
        $maps[] = ['cp_branch_num','>',$cp_branch_num];
        $ranking = model('cp_form_branch_month')->get_count($maps,'id');
        if(empty($ranking)){
            $ranking = 0;
        }
        return $ranking + 1;
    }
}